package system;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements Operation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        Scanner scan = new Scanner(System.in) ;
        System.out.println("输入你要借阅的图书的书名");
        String name = scan.nextLine() ;
        int currentSize = bookList.getUsedSize();
        for(int i = 0 ;i < currentSize ; i ++){
            Book book = bookList.getBook(i) ;
            if (book.getName().equals(name)) {
                if(book.getIsBorrowed() == true){
                    System.out.println("对不起，该书已被借走");
                    return ;
                }else{
                    book.setIsBorrowed(true);
                    System.out.println("借阅成功");
                    return ;
                }
            }
        }
        System.out.println("没有你要借阅的书籍");
    }
}
